package app.linksheet.feature.engine.core.rule.intentappopen

import android.content.Intent
import assertk.assertions.isEqualTo
import assertk.assertions.isInstanceOf
import assertk.assertions.prop
import app.linksheet.feature.engine.core.IntentEngineResult
import app.linksheet.feature.engine.core.UrlEngineResult
import app.linksheet.feature.engine.core.rule.LazyTestLinkEngine
import app.linksheet.feature.engine.core.rule.PostProcessorRule
import app.linksheet.feature.engine.core.rule.assertResult
import fe.std.uri.toStdUrlOrThrow
import kotlinx.coroutines.CoroutineDispatcher
import kotlin.getValue

class IntentAppOpenTestBase(dispatcher: CoroutineDispatcher, rule: PostProcessorRule) {
    private val engine by LazyTestLinkEngine(dispatcher, rule)

    suspend fun `test rule not matched`()  {
        val result = engine.process("https://linksheet.app".toStdUrlOrThrow())
        assertResult(result)
            .isInstanceOf<UrlEngineResult>()
            .prop(UrlEngineResult::url)
            .transform { it.toString() }
            .isEqualTo("https://linksheet.app")
    }

    suspend fun `test rule matched`()  {
        val result = engine.process("https://linksheet.app/fakevideo.mp4".toStdUrlOrThrow())

        assertResult(result)
            .isInstanceOf<IntentEngineResult>()
            .transform { it.intent }
            .prop(Intent::getDataString)
            .isEqualTo("https://linksheet.app/fakevideo.mp4")
    }
}
